﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ThuVien;
namespace TranTekBE.News
{
    public partial class Home : System.Web.UI.Page
    {
        public string tbtitle = "";
        public string tbimage = "";
        public string tbtime = "";
        public string tbcontent = "";
        public string tbcount = "";
        public string tbuser = "";
        public string tbid = "";



        public string sktitle = "";
        public string skimage = "";
        public string sktime = "";
        public string skcontent = "";
        public string skcount = "";
        public string skuser = "";
        public string skid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            int tbnew = 0, sknew = 0;
            DataSet datatop3 = FunctionsUtils.Database2.ExecuteQuery("Select top 3 * from tbl_News where Slider != '' order by ID desc");
            if (datatop3 != null && datatop3.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in datatop3.Tables[0].Rows)
                {
                    slide.Text += "<li><a href=\"Read.aspx?id="+ row[0].ToString() +"\"><img alt=\"\" src=\"Images/slider/" +row[6].ToString()+ "\">";
                    slide.Text += "<div class=\"header\">" + row[1].ToString() + "</div>";
                    slide.Text += "<div class=\"flex-caption\"><div class=\"desc\">";
                    slide.Text += "<h1><a href=\"Read.aspx?id=" + row[0].ToString() + "\">" + row[1].ToString() +"</a></h1>";
                    slide.Text += "<p>" + row[3].ToString() + "</p>";
                    slide.Text += "</div></div></li>";
                }
            }
            //Select top 1 * from tbl_News where ID not in ( select top 3 ID from tbl_News where Slider != '' order by ID desc) and  Slider != '' AND Loai = 0 order by ID desc 

            DataSet tb = FunctionsUtils.Database2.ExecuteQuery("Select top 1 * from tbl_News where ID not in ( select top 3 ID from tbl_News where Slider != '' order by ID desc) and  Slider != '' AND Loai = 0 order by ID desc");
            if (tb != null && tb.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in tb.Tables[0].Rows)
                {
                    tbnew = int.Parse(row[0].ToString());
                    tbid = row[0].ToString();
                    tbtitle = row[1].ToString();
                    tbimage = row[7].ToString();
                    tbcontent = row[3].ToString();
                    tbtime = row[5].ToString().Split(' ')[0];
                    tbuser = row[9].ToString();
                    tbcount = row[8].ToString();
                }
            }
            DataSet sk = FunctionsUtils.Database2.ExecuteQuery("Select top 1 * from tbl_News where ID not in ( select top 3 ID from tbl_News where Slider != '' order by ID desc) and  Slider != '' AND Loai = 1 order by ID desc");
            if (sk != null && sk.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in sk.Tables[0].Rows)
                {
                    sknew = int.Parse(row[0].ToString());
                    skid = row[0].ToString();
                    sktitle = row[1].ToString();
                    skimage = row[7].ToString();
                    skcontent = row[3].ToString();
                    sktime = row[5].ToString().Split(' ')[0];
                    skuser = row[9].ToString();
                    skcount = row[8].ToString();
                }
            }
            DataSet newer = FunctionsUtils.Database2.ExecuteQuery("select top 5 * from tbl_News where ID not in (select top 3 ID from tbl_News where slider != '' order by ID desc) order by id desc");
            if (newer != null && newer.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in newer.Tables[0].Rows)
                {
                    popular.Text += "<li><a href=\"Read.aspx?id=" + row[0].ToString() + "\">";
                    popular.Text += "<img src=\"Images/avatar/" + row[7].ToString() + "\"></a>";
                    popular.Text += "<h3><a href=\"Read.aspx?id=" + row[0].ToString() + "\">" + row[1].ToString() + "</a></h3>";//comments
                    popular.Text += "<span class=\"comments\">" + row[8].ToString() + "</span>";
                    popular.Text += "<span class=\"post-date\">" + row[5].ToString().Split(' ')[0] + "</span></li>";
                }
            }
            DataSet datarecent = FunctionsUtils.Database2.ExecuteQuery("select top 5 * from tbl_News order by Viewer desc");
            if (datarecent != null && datarecent.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in datarecent.Tables[0].Rows)
                {
                    recent.Text += "<li><a href=\"Read.aspx?id=" + row[0].ToString() + "\">";
                    recent.Text += "<img src=\"Images/avatar/" + row[7].ToString() + "\"></a>";
                    recent.Text += "<h3><a href=\"Read.aspx?id=" + row[0].ToString() + "\">" + row[1].ToString() + "</a></h3>";
                    recent.Text += "<span class=\"comments\">" + row[8].ToString() + "</span>";
                    recent.Text += "<span class=\"post-date\">" + row[5].ToString().Split(' ')[0] + "</span></li>";
                }
            }
        }
    }
}